package io.finer.erp.jeecg.purchase.vo;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.finer.erp.jeecg.purchase.entity.PurchaseOrder;
import io.finer.erp.jeecg.purchase.entity.PurchaseOrderLine;
import io.finer.erp.jeecg.purchase.entity.PurchaseRequestLine;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.system.vo.LoginUser;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Data
@ApiModel(value="PurchaseOrderPage对象", description="采购订单")
public class PurchaseOrderPage {

    @ApiModelProperty(value = "ID")
    private String id;

    @ApiModelProperty(value = "单据编号")
    private String billNo;

    @ApiModelProperty(value = "供应商")
    private String supplierId;

    @ApiModelProperty(value = "供应商编码")
    private String supplierCode;

    @ApiModelProperty(value = "供应商名称")
    private String supplierName;

    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern="yyyy-MM-dd")
    @ApiModelProperty(value = "单据日期")
    private Date billDate;

    @ApiModelProperty(value = "申请部门")
    private String sysOrgCode;

    @ApiModelProperty(value = "申请部门名称")
    private String departName;

    @ApiModelProperty(value = "申请人")
    private String buyer;

    @ApiModelProperty(value = "币种")
    private String currencyId;

    @ApiModelProperty(value = "币种编码")
    private String currencyCode;

    @ApiModelProperty(value = "币种名称")
    private String currencyName;

    @ApiModelProperty(value = "收货库位")
    private String destWarehouseId;

    @ApiModelProperty(value = "收获库位编码")
    private String destWarehouseCode;

    @ApiModelProperty(value = "收货库位名称")
    private String destWarehouseName;

    @ApiModelProperty(value = "收货地址")
    private String destShipAddressId;

    @ApiModelProperty(value = "收获地址编码")
    private String destShipAddressCode;

    @ApiModelProperty(value = "收获地址名称")
    private String destShipAddressName;

    @ApiModelProperty(value = "收单地址")
    private String destBillAddressId;

    @ApiModelProperty(value = "收单地址编码")
    private String destBillAddressCode;

    @ApiModelProperty(value = "收单地址名称")
    private String destBillAddressName;

    @ApiModelProperty(value = "紧急程度")
    private String emergencyLevel;

    @ApiModelProperty(value = "单据处理状态")
    private String billProcStatus;

    @ApiModelProperty(value = "合计")
    private BigDecimal totalAmount;

    @ApiModelProperty(value = "税额")
    private BigDecimal taxAmount;

    @ApiModelProperty(value = "已取消金额")
    private BigDecimal cancelledAmount;

    @ApiModelProperty(value = "净合计")
    private BigDecimal netAmount;

    @ApiModelProperty(value = "对账单地址")
    private String billAddressId;

    @ApiModelProperty(value = "对账单地址编码")
    private String billAddressCode;

    @ApiModelProperty(value = "对账单地址名称")
    private String billAddressName;

    @ApiModelProperty(value = "供应商联系人")
    private String supplierContact;

    @ApiModelProperty(value = "合同信息")
    private String contract;

    @ApiModelProperty(value = "付款条款")
    private String paymentTermsId;

    @ApiModelProperty(value = "付款条款编码")
    private String paymentTermsCode;

    @ApiModelProperty(value = "付款条款名称")
    private String paymentTermsName;

    @ApiModelProperty(value = "法律条款")
    private String clauseId;

    @ApiModelProperty(value = "法律条款编码")
    private String clauseCode;

    @ApiModelProperty(value = "法律条款名称")
    private String clauseName;

    @ApiModelProperty(value = "作废原因")
    private String invalidationReason;

    @ApiModelProperty(value = "附件")
    private String attachment;

    @ApiModelProperty(value = "备注")
    private String remark;

    @ApiModelProperty(value = "来源")
    private String source;

    @ApiModelProperty(value = "制单人")
    private String createBy;

    @ApiModelProperty(value = "创建时间")
    private Date createTime;

    @ApiModelProperty(value = "修改人")
    private String updateBy;

    @ApiModelProperty(value = "修改时间")
    private Date updateTime;

    @ApiModelProperty(value = "版本")
    private Integer version;

    @ApiModelProperty(value = "可执行操作")
    private Map actionsEnabled;

    public Map getActionsEnabled() {
        if (id == null) {
            return null;
        }
        if(actionsEnabled != null){
            return actionsEnabled;
        }

        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();

        HashMap<String, Boolean> map = new HashMap<String, Boolean>();
        boolean b = billProcStatus == "create" && createBy == sysUser.getUsername();
        map.put("edit", b);
        map.put("delete", b);

        actionsEnabled = map;
        return map;
    }

    @ApiModelProperty(value = "采购订单行")
    private List<PurchaseOrderLine> purchaseOrderLineList;
}
